package org.karelun.gef.actions;

import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.karelun.gef.commands.PasteNodeCommand;
import org.karelun.gef.editors.ClassDiagramEditor;

public class PasteAction extends SelectionAction {

	private IWorkbenchWindow window;

	public PasteAction(IWorkbenchPart part) {
		super(part);
		window = part.getSite().getWorkbenchWindow();
	}

	protected void init() {
		super.init();
		setId(ActionFactory.PASTE.getId());
		setEnabled(false);
	}

	protected boolean calculateEnabled() {
		return true;
	}

	public void run() {
		if (window == null)
			return;
		IWorkbenchPage page = window.getActivePage();
		IEditorPart editor = page.getActiveEditor();
		PasteNodeCommand command = new PasteNodeCommand(editor);
		// command.execute();
		IWorkbenchPart part = getWorkbenchPart();
		if (part instanceof ClassDiagramEditor) {
			getCommandStack().execute(command);
		}
	}
}
